package com.sc.highspeed.service;

import com.sc.highspeed.db.dao.UserDao;
import com.sc.highspeed.db.model.UserModel;
import com.sc.highspeed.tools.MD5Tool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.UnsupportedEncodingException;
import java.util.List;

/**
 * Created by Admin on 2017/11/27.
 */
@Service
public class UserService {

    @Autowired
    private UserDao userDao;

    public UserModel getUserByNumber(String number) {
        return userDao.getUserByNumber(number);
    }

    public UserModel getUserByUsername(String username) {
        return userDao.getUserByUsername(username);
    }

    public List<UserModel> getUserList() {
        return userDao.getUserList();
    }

    public int insertUser(UserModel userModel) {
//        String password = userModel.getPassword();
//        String md5Password = "";
//        try {
//            md5Password = MD5Tool.md5Encode(password);
//        } catch (UnsupportedEncodingException e) {
//            e.printStackTrace();
//        }
//        userModel.setPassword(md5Password);
        return userDao.insertUser(userModel);
    }

    public int updateUserByUsername(UserModel userModel) {
        return userDao.updateUserByUsername(userModel);
    }

    public int deleteUserByNumber(String number) {
        return userDao.deleteUserByNumber(number);
    }

    public List<UserModel> getUserListByOrg(String organization) {
        return userDao.getUserListByOrg(organization);
    }

    public List<UserModel> getUserListByGroupAndOrg(String userGroup, String organization) {
        return userDao.getUserListByGroupAndOrg(userGroup, organization);
    }

    public int updateUserGroupByNumber(String gourpName, String number) {
        return userDao.updateUserGroupByNumber(gourpName, number);
    }

    public int updateUserOrganization(String username, String organization) {
        return userDao.updateUserOrganization(username, organization);
    }

    public int deleteUserByUsername(String username) {
        return userDao.deleteUserByUsername(username);
    }

}
